<?php
class PdetailsController extends AppController {

    public $helpers = array('Html', 'Form');
    public $components = array('Session');

    public function index() {
        $pageTitle ="Worldwide Seventh-day Adventist Church - Kwabrafoso: Members Personal Details List";
        $in_record_data = $this->Pdetail->find('all');
        $this->set(compact('in_record_data','pageTitle'));
    }

    
    public function add(){
    $pageTitle ="Worldwide Seventh-day Adventist Church - Kwabrafoso: Add Members' Personal Details";
     if($_POST){
       // pr($_POST);
        $data['Pdetail'] = array(
            'nid' => $_POST['nid'],
            'nhis' => $_POST['nhis'],
            'toh' => $_POST['toh'],
            'sname' => $_POST['sname'],
            'mname' => $_POST['mname'],
            'fname' => $_POST['fname'],
            'pix' => $_POST['pix'],
            'dob' => $_POST['dob'],
            'pob' => $_POST['pob'],
            'age' => $_POST['age'],
            'country' => $_POST['country'],
            'region' => $_POST['region'],
            'district' => $_POST['district'],
            'town' => $_POST['town'],
            'profession' => $_POST['profession'],
            'mstatus' => $_POST['mstatus'],
            'mshipno' => $_POST['mshipno'],
            'tel' => $_POST['tel'],
            'mfon' => $_POST['mfon'],
            'email' => $_POST['email']
        );

        if(!$this->Pdetail->save($data)){
            $this->Session->setFlash('Error Saving Personal Details');
        }else{
             $this->Session->setFlash('Personal Details Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','errorMsg'));
}
    
    // A functin to delete Personal Details
    public function delete($id = null)
    {
       if (!$id) 
       {
        $this->Session->setFlash('Invalid id for Personal Details');
        $this->redirect(array('action' => 'index'));
    }
    if ($this->Pdetail->delete($id)) 
    {
        $this->Session->setFlash('Personal Details Deleted Please');
    } else 
    {
        $this->Session->setFlash(__('Personal Detail Not Deleted', true));
    }
    $this->redirect(array('action' => 'index'));
}

    // A functin to edit Personal Details
    function edit($id = null){
    $record_id = $id;
    $conditions = array('Pdetail.id' => $record_id);
    $record = $this->Pdetail->find('first', array('conditions' => $conditions, 'recursive' => 1));
   // pr($record);
            
     $pageTitle ="Worldwide Seventh-day Adventist Church - Kwabrafoso: Edit Personal Details";
     if($_POST){
        //pr($_POST);
        $data['Pdetail'] = array(
            'nid' => $_POST['nid'],
            'nhis' => $_POST['nhis'],
            'toh' => $_POST['toh'],
            'sname' => $_POST['sname'],
            'mname' => $_POST['mname'],
            'fname' => $_POST['fname'],
            'pix' => $_POST['pix'],
            'dob' => $_POST['dob'],
            'pob' => $_POST['pob'],
            'age' => $_POST['age'],
            'country' => $_POST['country'],
            'region' => $_POST['region'],
            'district' => $_POST['district'],
            'town' => $_POST['town'],
            'profession' => $_POST['profession'],
            'mstatus' => $_POST['mstatus'],
            'mshipno' => $_POST['mshipno'],
            'tel' => $_POST['tel'],
            'mfon' => $_POST['mfon'],
            'email' => $_POST['email']
        );

        if(!$this->Pdetail->save($data)){
            $this->Session->setFlash('Error Saving Data');
        }else{
             $this->Session->setFlash('Data Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','record'));
}

     // A functin to view Pernal Detail Records
    public function view($id) {
    if (!$id) {
        throw new NotFoundException(__('Invalid Record'));
    }

    $pdetail = $this->Pdetail->findById($id);
    if (!$pdetail) {
        throw new NotFoundException(__('Invalid Record'));
    }
    $this->set('Pdetail', $pdetail);
}

function report($id = null){
    $record_id = $id;
    $conditions = array('Pdetail.id' => $record_id);
    $record = $this->Pdetail->find('first', array('conditions' => $conditions, 'recursive' => 1));
//    pr($record);

}

}
?>